/***********************************************************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2006-2009 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
*********************************************************************************************************************//*!
*
* @file   TSS_SensorTSI.c
*
* @brief  Contains functions to Perform the sensing to the electrodes and set the status for each electrode
*
* @version 1.0.81.0
*
* @date Sep-20-2012
*
*
***********************************************************************************************************************/

#include "TSS_SensorTSI.h"

#if TSS_DETECT_METHOD(TSI)

  #if TSS_HCS08_MCU || TSS_CFV1_MCU

    /***************** ROM & RAM Data definition *******************/

    #if TSS_N_ELECTRODES > 0
      #if TSS_DETECT_EL_METHOD(0,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E0_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(0) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E0_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 1
      #if TSS_DETECT_EL_METHOD(1,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E1_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(1) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E1_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 2
      #if TSS_DETECT_EL_METHOD(2,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E2_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(2) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E2_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 3
      #if TSS_DETECT_EL_METHOD(3,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E3_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(3) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E3_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 4
      #if TSS_DETECT_EL_METHOD(4,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E4_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(4) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E4_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 5
      #if TSS_DETECT_EL_METHOD(5,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E5_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(5) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E5_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 6
      #if TSS_DETECT_EL_METHOD(6,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E6_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(6) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E6_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 7
      #if TSS_DETECT_EL_METHOD(7,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E7_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(7) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E7_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 8
      #if TSS_DETECT_EL_METHOD(8,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E8_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(8) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E8_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 9
      #if TSS_DETECT_EL_METHOD(9,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E9_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(9) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E9_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 10
      #if TSS_DETECT_EL_METHOD(10,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E10_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(10) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E10_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 11
      #if TSS_DETECT_EL_METHOD(11,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E11_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(11) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E11_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 12
      #if TSS_DETECT_EL_METHOD(12,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E12_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(12) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E12_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 13
      #if TSS_DETECT_EL_METHOD(13,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E13_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(13) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E13_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 14
      #if TSS_DETECT_EL_METHOD(14,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E14_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(14) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E14_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 15
      #if TSS_DETECT_EL_METHOD(15,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E15_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(15) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E15_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 16
      #if TSS_DETECT_EL_METHOD(16,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E16_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(16) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E16_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 17
      #if TSS_DETECT_EL_METHOD(17,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E17_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(17) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E17_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 18
      #if TSS_DETECT_EL_METHOD(18,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E18_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(18) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E18_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 19
      #if TSS_DETECT_EL_METHOD(19,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E19_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(19) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E19_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 20
      #if TSS_DETECT_EL_METHOD(20,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E20_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(20) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E20_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 21
      #if TSS_DETECT_EL_METHOD(21,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E21_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(21) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E21_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 22
      #if TSS_DETECT_EL_METHOD(22,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E22_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(22) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E22_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 23
      #if TSS_DETECT_EL_METHOD(23,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E23_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(23) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E23_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 24
      #if TSS_DETECT_EL_METHOD(24,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E24_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(24) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E24_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 25
      #if TSS_DETECT_EL_METHOD(25,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E25_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(25) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E25_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 26
      #if TSS_DETECT_EL_METHOD(26,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E26_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(26) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E26_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 27
      #if TSS_DETECT_EL_METHOD(27,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E27_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(27) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E27_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 28
      #if TSS_DETECT_EL_METHOD(28,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E28_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(28) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E28_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 29
      #if TSS_DETECT_EL_METHOD(29,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E29_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(29) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E29_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 30
      #if TSS_DETECT_EL_METHOD(30,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E30_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(30) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E30_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 31
      #if TSS_DETECT_EL_METHOD(31,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E31_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(31) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E31_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 32
      #if TSS_DETECT_EL_METHOD(32,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E32_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(32) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E32_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 33
      #if TSS_DETECT_EL_METHOD(33,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E33_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(33) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E33_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 34
      #if TSS_DETECT_EL_METHOD(34,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E34_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(34) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E34_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 35
      #if TSS_DETECT_EL_METHOD(35,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E35_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(35) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E35_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 36
      #if TSS_DETECT_EL_METHOD(36,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E36_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(36) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E36_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 37
      #if TSS_DETECT_EL_METHOD(37,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E37_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(37) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E37_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 38
      #if TSS_DETECT_EL_METHOD(38,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E38_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(38) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E38_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 39
      #if TSS_DETECT_EL_METHOD(39,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E39_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(39) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E39_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 40
      #if TSS_DETECT_EL_METHOD(40,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E40_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(40) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E40_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 41
      #if TSS_DETECT_EL_METHOD(41,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E41_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(41) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E41_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 42
      #if TSS_DETECT_EL_METHOD(42,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E42_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(42) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E42_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 43
      #if TSS_DETECT_EL_METHOD(43,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E43_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(43) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E43_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 44
      #if TSS_DETECT_EL_METHOD(44,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E44_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(44) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E44_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 45
      #if TSS_DETECT_EL_METHOD(45,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E45_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(45) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E45_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 46
      #if TSS_DETECT_EL_METHOD(46,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E46_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(46) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E46_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 47
      #if TSS_DETECT_EL_METHOD(47,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E47_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(47) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E47_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 48
      #if TSS_DETECT_EL_METHOD(48,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E48_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(48) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E48_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 49
      #if TSS_DETECT_EL_METHOD(49,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E49_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(49) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E49_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 50
      #if TSS_DETECT_EL_METHOD(50,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E50_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(50) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E50_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 51
      #if TSS_DETECT_EL_METHOD(51,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E51_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(51) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E51_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 52
      #if TSS_DETECT_EL_METHOD(52,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E52_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(52) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E52_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 53
      #if TSS_DETECT_EL_METHOD(53,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E53_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(53) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E53_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 54
      #if TSS_DETECT_EL_METHOD(54,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E54_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(54) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E54_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 55
      #if TSS_DETECT_EL_METHOD(55,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E55_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(55) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E55_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 56
      #if TSS_DETECT_EL_METHOD(56,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E56_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(56) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E56_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 57
      #if TSS_DETECT_EL_METHOD(57,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E57_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(57) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E57_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 58
      #if TSS_DETECT_EL_METHOD(58,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E58_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(58) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E58_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 59
      #if TSS_DETECT_EL_METHOD(59,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E59_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(59) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E59_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 60
      #if TSS_DETECT_EL_METHOD(60,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E60_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(60) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E60_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 61
      #if TSS_DETECT_EL_METHOD(61,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E61_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(61) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E61_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 62
      #if TSS_DETECT_EL_METHOD(62,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E62_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(62) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E62_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 63
      #if TSS_DETECT_EL_METHOD(63,TSI)
          const TSS_TSI_ELECTRODE_ROMDATA TSS_E63_ROMDATA_CONTEXT = { TSS_GET_EL_MODULE_ID(63) };
              TSS_TSI_ELECTRODE_RAMDATA TSS_E63_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

  #elif TSS_KINETIS_MCU || TSS_CFM_MCU

    /************************ Prototypes **************************/

    UINT8 TSI_MethodControl(UINT8 u8ElNum, UINT8 u8Command);

    /*******************  Modules definition **********************/

    #if TSS_DETECT_MODULE(TSI)
      #if TSS_KINETIS_MCU
        const TSS_TSI_METHOD_ROMDATA TSS_TSI_METHOD_ROMDATA_CONTEXT = {TSI_MethodControl, (UINT32*) TSI_BASE_PTR, INT_TSI-16, TSS_DETECT_AUTOTRIGGER_SOURCE_USAGE(TSI), TSS_DETECT_LOWPOWER_USAGE(TSI)}; 
      #elif TSS_CFM_MCU
        const TSS_TSI_METHOD_ROMDATA TSS_TSI_METHOD_ROMDATA_CONTEXT = {TSI_MethodControl, (UINT32*) TSI_BASE_PTR, Vtsi-16, TSS_DETECT_AUTOTRIGGER_SOURCE_USAGE(TSI), TSS_DETECT_LOWPOWER_USAGE(TSI)};
      #endif
      volatile TSS_TSI_METHOD_RAMDATA TSS_TSI_METHOD_RAMDATA_CONTEXT = {TSI_EOSF_STATE_NONE};
    #endif
    #if TSS_DETECT_MODULE(TSI0)
      #if TSS_KINETIS_MCU
        const TSS_TSI_METHOD_ROMDATA TSS_TSI0_METHOD_ROMDATA_CONTEXT = {TSI_MethodControl, (UINT32*) TSI0_BASE_PTR, INT_TSI0-16, TSS_DETECT_AUTOTRIGGER_SOURCE_USAGE(TSI0), TSS_DETECT_LOWPOWER_USAGE(TSI0)};    
      #elif TSS_CFM_MCU
        const TSS_TSI_METHOD_ROMDATA TSS_TSI0_METHOD_ROMDATA_CONTEXT = {TSI_MethodControl, (UINT32*) TSI0_BASE_PTR, Vtsi0-16, TSS_DETECT_AUTOTRIGGER_SOURCE_USAGE(TSI0), TSS_DETECT_LOWPOWER_USAGE(TSI0)};    
      #endif
      volatile TSS_TSI_METHOD_RAMDATA TSS_TSI0_METHOD_RAMDATA_CONTEXT = {TSI_EOSF_STATE_NONE};
    #endif
    #if TSS_DETECT_MODULE(TSI1)
      #if TSS_KINETIS_MCU
        const TSS_TSI_METHOD_ROMDATA TSS_TSI1_METHOD_ROMDATA_CONTEXT = {TSI_MethodControl, (UINT32*) TSI1_BASE_PTR, INT_TSI1-16, TSS_DETECT_AUTOTRIGGER_SOURCE_USAGE(TSI1), TSS_DETECT_LOWPOWER_USAGE(TSI1)};        
      #elif TSS_CFM_MCU
        const TSS_TSI_METHOD_ROMDATA TSS_TSI1_METHOD_ROMDATA_CONTEXT = {TSI_MethodControl, (UINT32*) TSI1_BASE_PTR, Vtsi1-16, TSS_DETECT_AUTOTRIGGER_SOURCE_USAGE(TSI1), TSS_DETECT_LOWPOWER_USAGE(TSI1)};    
      #endif
      volatile TSS_TSI_METHOD_RAMDATA TSS_TSI1_METHOD_RAMDATA_CONTEXT = {TSI_EOSF_STATE_NONE};
    #endif

    /***************** Method Memory Data Decoding Macros **********/

    #define TSS_GET_TSI_METHOD_DATA_CONTEXT_RESULT(memory,res)       TSS_##res##_METHOD_##memory##DATA_CONTEXT
    #define TSS_GET_TSI_METHOD_DATA_CONTEXT_CONV(memory,text)        TSS_GET_TSI_METHOD_DATA_CONTEXT_RESULT(memory,text)
    #define TSS_GET_TSI_METHOD_DATA_CONTEXT_TYPE(memory,module)      TSS_GET_TSI_METHOD_DATA_CONTEXT_CONV(memory,module)

    #define TSS_GET_TSI_METHOD_DATA_CONTEXT(memory,el)               TSS_GET_TSI_METHOD_DATA_CONTEXT_TYPE(memory, TSS_TSI_EL_MODULE_NAME(el))

    /***************** ROM & RAM Data definition *******************/

    #if TSS_N_ELECTRODES > 0
      #if TSS_DETECT_EL_METHOD(0,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E0_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,0), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,0), TSS_TSI_EL_CHANNEL_NUM(0)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E0_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 1
      #if TSS_DETECT_EL_METHOD(1,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E1_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,1), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,1), TSS_TSI_EL_CHANNEL_NUM(1)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E1_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 2
      #if TSS_DETECT_EL_METHOD(2,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E2_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,2), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,2), TSS_TSI_EL_CHANNEL_NUM(2)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E2_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 3
      #if TSS_DETECT_EL_METHOD(3,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E3_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,3), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,3), TSS_TSI_EL_CHANNEL_NUM(3)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E3_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 4
      #if TSS_DETECT_EL_METHOD(4,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E4_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,4), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,4), TSS_TSI_EL_CHANNEL_NUM(4)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E4_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 5
      #if TSS_DETECT_EL_METHOD(5,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E5_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,5), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,5), TSS_TSI_EL_CHANNEL_NUM(5)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E5_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 6
      #if TSS_DETECT_EL_METHOD(6,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E6_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,6), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,6), TSS_TSI_EL_CHANNEL_NUM(6)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E6_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 7
      #if TSS_DETECT_EL_METHOD(7,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E7_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,7), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,7), TSS_TSI_EL_CHANNEL_NUM(7)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E7_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 8
      #if TSS_DETECT_EL_METHOD(8,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E8_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,8), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,8), TSS_TSI_EL_CHANNEL_NUM(8)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E8_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 9
      #if TSS_DETECT_EL_METHOD(9,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E9_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,9), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,9), TSS_TSI_EL_CHANNEL_NUM(9)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E9_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 10
      #if TSS_DETECT_EL_METHOD(10,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E10_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,10), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,10), TSS_TSI_EL_CHANNEL_NUM(10)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E10_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 11
      #if TSS_DETECT_EL_METHOD(11,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E11_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,11), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,11), TSS_TSI_EL_CHANNEL_NUM(11)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E11_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 12
      #if TSS_DETECT_EL_METHOD(12,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E12_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,12), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,12), TSS_TSI_EL_CHANNEL_NUM(12)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E12_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 13
      #if TSS_DETECT_EL_METHOD(13,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E13_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,13), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,13), TSS_TSI_EL_CHANNEL_NUM(13)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E13_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 14
      #if TSS_DETECT_EL_METHOD(14,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E14_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,14), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,14), TSS_TSI_EL_CHANNEL_NUM(14)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E14_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 15
      #if TSS_DETECT_EL_METHOD(15,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E15_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,15), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,15), TSS_TSI_EL_CHANNEL_NUM(15)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E15_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 16
      #if TSS_DETECT_EL_METHOD(16,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E16_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,16), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,16), TSS_TSI_EL_CHANNEL_NUM(16)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E16_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 17
      #if TSS_DETECT_EL_METHOD(17,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E17_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,17), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,17), TSS_TSI_EL_CHANNEL_NUM(17)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E17_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 18
      #if TSS_DETECT_EL_METHOD(18,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E18_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,18), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,18), TSS_TSI_EL_CHANNEL_NUM(18)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E18_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 19
      #if TSS_DETECT_EL_METHOD(19,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E19_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,19), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,19), TSS_TSI_EL_CHANNEL_NUM(19)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E19_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 20
      #if TSS_DETECT_EL_METHOD(20,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E20_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,20), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,20), TSS_TSI_EL_CHANNEL_NUM(20)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E20_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 21
      #if TSS_DETECT_EL_METHOD(21,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E21_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,21), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,21), TSS_TSI_EL_CHANNEL_NUM(21)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E21_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 22
      #if TSS_DETECT_EL_METHOD(22,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E22_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,22), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,22), TSS_TSI_EL_CHANNEL_NUM(22)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E22_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 23
      #if TSS_DETECT_EL_METHOD(23,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E23_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,23), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,23), TSS_TSI_EL_CHANNEL_NUM(23)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E23_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 24
      #if TSS_DETECT_EL_METHOD(24,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E24_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,24), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,24), TSS_TSI_EL_CHANNEL_NUM(24)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E24_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 25
      #if TSS_DETECT_EL_METHOD(25,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E25_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,25), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,25), TSS_TSI_EL_CHANNEL_NUM(25)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E25_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 26
      #if TSS_DETECT_EL_METHOD(26,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E26_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,26), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,26), TSS_TSI_EL_CHANNEL_NUM(26)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E26_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 27
      #if TSS_DETECT_EL_METHOD(27,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E27_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,27), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,27), TSS_TSI_EL_CHANNEL_NUM(27)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E27_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 28
      #if TSS_DETECT_EL_METHOD(28,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E28_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,28), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,28), TSS_TSI_EL_CHANNEL_NUM(28)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E28_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 29
      #if TSS_DETECT_EL_METHOD(29,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E29_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,29), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,29), TSS_TSI_EL_CHANNEL_NUM(29)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E29_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 30
      #if TSS_DETECT_EL_METHOD(30,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E30_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,30), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,30), TSS_TSI_EL_CHANNEL_NUM(30)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E30_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 31
      #if TSS_DETECT_EL_METHOD(31,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E31_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,31), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,31), TSS_TSI_EL_CHANNEL_NUM(31)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E31_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 32
      #if TSS_DETECT_EL_METHOD(32,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E32_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,32), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,32), TSS_TSI_EL_CHANNEL_NUM(32)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E32_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 33
      #if TSS_DETECT_EL_METHOD(33,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E33_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,33), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,33), TSS_TSI_EL_CHANNEL_NUM(33)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E33_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 34
      #if TSS_DETECT_EL_METHOD(34,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E34_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,34), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,34), TSS_TSI_EL_CHANNEL_NUM(34)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E34_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 35
      #if TSS_DETECT_EL_METHOD(35,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E35_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,35), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,35), TSS_TSI_EL_CHANNEL_NUM(35)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E35_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 36
      #if TSS_DETECT_EL_METHOD(36,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E36_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,36), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,36), TSS_TSI_EL_CHANNEL_NUM(36)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E36_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 37
      #if TSS_DETECT_EL_METHOD(37,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E37_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,37), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,37), TSS_TSI_EL_CHANNEL_NUM(37)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E37_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 38
      #if TSS_DETECT_EL_METHOD(38,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E38_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,38), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,38), TSS_TSI_EL_CHANNEL_NUM(38)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E38_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 39
      #if TSS_DETECT_EL_METHOD(39,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E39_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,39), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,39), TSS_TSI_EL_CHANNEL_NUM(39)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E39_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 40
      #if TSS_DETECT_EL_METHOD(40,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E40_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,40), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,40), TSS_TSI_EL_CHANNEL_NUM(40)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E40_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 41
      #if TSS_DETECT_EL_METHOD(41,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E41_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,41), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,41), TSS_TSI_EL_CHANNEL_NUM(41)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E41_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 42
      #if TSS_DETECT_EL_METHOD(42,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E42_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,42), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,42), TSS_TSI_EL_CHANNEL_NUM(42)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E42_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 43
      #if TSS_DETECT_EL_METHOD(43,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E43_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,43), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,43), TSS_TSI_EL_CHANNEL_NUM(43)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E43_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 44
      #if TSS_DETECT_EL_METHOD(44,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E44_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,44), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,44), TSS_TSI_EL_CHANNEL_NUM(44)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E44_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 45
      #if TSS_DETECT_EL_METHOD(45,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E45_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,45), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,45), TSS_TSI_EL_CHANNEL_NUM(45)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E45_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 46
      #if TSS_DETECT_EL_METHOD(46,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E46_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,46), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,46), TSS_TSI_EL_CHANNEL_NUM(46)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E46_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 47
      #if TSS_DETECT_EL_METHOD(47,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E47_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,47), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,47), TSS_TSI_EL_CHANNEL_NUM(47)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E47_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 48
      #if TSS_DETECT_EL_METHOD(48,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E48_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,48), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,48), TSS_TSI_EL_CHANNEL_NUM(48)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E48_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 49
      #if TSS_DETECT_EL_METHOD(49,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E49_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,49), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,49), TSS_TSI_EL_CHANNEL_NUM(49)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E49_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 50
      #if TSS_DETECT_EL_METHOD(50,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E50_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,50), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,50), TSS_TSI_EL_CHANNEL_NUM(50)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E50_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 51
      #if TSS_DETECT_EL_METHOD(51,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E51_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,51), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,51), TSS_TSI_EL_CHANNEL_NUM(51)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E51_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 52
      #if TSS_DETECT_EL_METHOD(52,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E52_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,52), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,52), TSS_TSI_EL_CHANNEL_NUM(52)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E52_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 53
      #if TSS_DETECT_EL_METHOD(53,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E53_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,53), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,53), TSS_TSI_EL_CHANNEL_NUM(53)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E53_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 54
      #if TSS_DETECT_EL_METHOD(54,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E54_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,54), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,54), TSS_TSI_EL_CHANNEL_NUM(54)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E54_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 55
      #if TSS_DETECT_EL_METHOD(55,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E55_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,55), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,55), TSS_TSI_EL_CHANNEL_NUM(55)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E55_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 56
      #if TSS_DETECT_EL_METHOD(56,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E56_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,56), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,56), TSS_TSI_EL_CHANNEL_NUM(56)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E56_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 57
      #if TSS_DETECT_EL_METHOD(57,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E57_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,57), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,57), TSS_TSI_EL_CHANNEL_NUM(57)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E57_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 58
      #if TSS_DETECT_EL_METHOD(58,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E58_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,58), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,58), TSS_TSI_EL_CHANNEL_NUM(58)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E58_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 59
      #if TSS_DETECT_EL_METHOD(59,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E59_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,59), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,59), TSS_TSI_EL_CHANNEL_NUM(59)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E59_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 60
      #if TSS_DETECT_EL_METHOD(60,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E60_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,60), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,60), TSS_TSI_EL_CHANNEL_NUM(60)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E60_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 61
      #if TSS_DETECT_EL_METHOD(61,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E61_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,61), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,61), TSS_TSI_EL_CHANNEL_NUM(61)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E61_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 62
      #if TSS_DETECT_EL_METHOD(62,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E62_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,62), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,62), TSS_TSI_EL_CHANNEL_NUM(62)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E62_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    #if TSS_N_ELECTRODES > 63
      #if TSS_DETECT_EL_METHOD(63,TSI)
        const TSS_TSI_ELECTRODE_ROMDATA TSS_E63_ROMDATA_CONTEXT = { &TSS_GET_TSI_METHOD_DATA_CONTEXT(ROM,63), &TSS_GET_TSI_METHOD_DATA_CONTEXT(RAM,63), TSS_TSI_EL_CHANNEL_NUM(63)};
              TSS_TSI_ELECTRODE_RAMDATA TSS_E63_RAMDATA_CONTEXT = { 0u };
      #endif
    #endif

    /***************************************************************************//*!
    *                                 Types
    ****************************************************************************/

    /* TSI Recalibration Struct */

    typedef struct {
      UINT8 u8TSIPS;
      UINT8 u8TSIExtChrg;
      UINT16 u16Distance;
    } TSI_CALIBRATION;
    
    /***************************************************************************//*!
    *        Table for calculation of Internal Reference OSC Current
    ****************************************************************************/
     #if (TSS_TSI_VERSION == 1)
    const UINT8 u8RefChrgCalcTable[8][8] = {
      {10, 15, 20, 25, 30, 40, 50, 60},
      {12, 18, 24, 30, 36, 48, 60, 72},
      {14, 21, 28, 35, 42, 56, 70, 84},
      {16, 24, 32, 40, 48, 64, 80, 96},
      {18, 27, 36, 45, 54, 72, 90, 108},
      {20, 30, 40, 50, 60, 80, 100, 120},
      {22, 33, 44, 55, 66, 88, 110, 132},
      {24, 36, 48, 60, 72, 96, 120, 144}
    };
    #endif
    /************************** Prototypes ***************************/

    UINT8 TSI_InitModule(TSS_TSI_MemMapPtr psModuleStruct);
    UINT8 TSI_SetNSamples(TSS_TSI_MemMapPtr psModuleStruct);
    UINT8 TSI_InitLowPower(TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct);
    UINT8 TSI_InitPEN(TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct);
    UINT8 TSI_Recalibrate(TSS_TSI_MemMapPtr psModuleStruct, TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct);
    UINT8 TSI_InitThresholds(TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct);
    UINT8 TSI_InitTrigger(TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct, TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct);
    UINT8 TSI_ReadCounter(TSS_TSI_ELECTRODE_ROMDATA *psElectrodeROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct, TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct);

    /***************************************************************************//*!
    *
    * @brief  Control function for TSI General Initialization
    *
    * @param  psModuleStruct - Specification of TSI module
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_InitModule(TSS_TSI_MemMapPtr psModuleStruct)
    {
      UINT8 u8result = TSS_INIT_STATUS_OK;

      /* GENCS Settings */
      psModuleStruct->GENCS = 0; /* Erase GENCS - Turn OFF TSI*/
      /* Low Power TSI definition */
#if (TSS_TSI_VERSION==1) || (TSS_TSI_VERSION==2)
      psModuleStruct->GENCS |= TSI_GENCS_LPCLKS(TSS_TSI_LPCLKS);        /* Set Low Power Mode Clock Source 0 = LPOCLK, 1 = VLPOSCCLK */
#endif
      /* SCANC Settings */
      psModuleStruct->SCANC = 0; /* Erase SCANC */
      /* Active Mode Clock Settings */
      psModuleStruct->SCANC |= TSI_SCANC_AMCLKS(TSS_TSI_AMCLKS);        /* Set Input Active Mode Clock Source - Set by the user 0 = BUSclk, 1 = MCGIRCLK, 2 = OSCERCLK, 3 - NA */ 
      psModuleStruct->SCANC |= TSI_SCANC_AMPSC(TSS_TSI_AMPSC);          /* Set Input Active Mode Clock Prescaler - Set by the user 1 = divide 1, 7 = divide 128 */
    #if (TSS_TSI_VERSION==1)
      psModuleStruct->SCANC |= TSI_SCANC_AMCLKDIV(TSS_TSI_AMCLKDIV);    /* Set Input Active Mode Clock Divider - Set by the user 0 = divide 1, 1 = divide 2048 */
      /* Both OSC settings */
      psModuleStruct->SCANC |= TSI_SCANC_DELVOL(TSS_TSI_DELVOL);        /* Delta Voltage  settings for ElOSC and RefOSC 0 = 100mV, 7 = 600mV */
      /* TSI RefOSC definitions */
      psModuleStruct->SCANC |= TSI_SCANC_CAPTRM(TSS_TSI_SCANC_CAPTRM);        /* Internal Capacitance Trim value 0=0.5pF,7=1.2pF */
    #endif
    #if (TSS_TSI_VERSION==2)
      psModuleStruct->SCANC |= TSI_SCANC_REFCHRG(TSS_TSI_SCANC_REFCHRG); /* Internal Ref OSC Charge Current 0= 1uA, 16 = 32uA */
    #elif (TSS_TSI_VERSION==3)
      psModuleStruct->SCANC |= TSI_SCANC_REFCHRG(TSS_TSI_SCANC_REFCHRG); /* Internal Ref OSC Charge Current 0= 0.5uA, 7 = 64uA */
      psModuleStruct->SCANC |= TSI_SCANC_DVOLT(TSS_TSI_DVOLT);           /* Voltage Rails */
    #elif (TSS_TSI_VERSION==1)
      psModuleStruct->SCANC |= TSI_SCANC_REFCHRG(TSS_CALC_TSI_REFCHRG_TABLE); /* Internal Ref OSC Charge Current 0= 1uA, 31 = 32uA */ 
    #endif
      return u8result;
    }

    /***************************************************************************//*!
    *
    * @brief  Control function for TSI Number of Samples Settings
    *
    * @param  psModuleStruct - Specification of TSI module
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_SetNSamples(TSS_TSI_MemMapPtr psModuleStruct)
    {
      UINT8 u8result = TSS_INIT_STATUS_OK;
      UINT8 u8NSamples;

      psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK;          /* Turn OFF TSI Module*/;
      psModuleStruct->GENCS &= ~TSI_GENCS_NSCN_MASK;           /* Erase NSCN */
      /* Number of Samples settings */
      u8NSamples = tss_CSSys.NSamples;
      psModuleStruct->GENCS |= TSI_GENCS_NSCN(u8NSamples-1u);  /* Number of Consecutive Scans per Electrode 0 = 1 scan, 32 = 32 scans*/

      return u8result;
    }

    /***************************************************************************//*!
    *
    * @brief  Control function for TSI Low Power Settings
    *
    * @param  *psMethodROMDataStruct - Specificcation of ROMDATA Struct
    *         psModuleStruct - Specification of TSI module
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_InitLowPower(TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct)
    {
      UINT8 u8result = TSS_INIT_STATUS_OK;
      UINT8 u8LowPowerScanPeriod;

      psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK; /* Turn OFF TSI Module*/;
#if (TSS_TSI_VERSION==1) || (TSS_TSI_VERSION==2)
      psModuleStruct->GENCS &= ~TSI_GENCS_LPSCNITV_MASK; /* Erase LPSCNITV */
#endif
      if (psMethodROMDataStruct->tsi_u8LowPowerControlSource == 1u) /* This TSI module is Low Power Control source */
      {
        /* Low Power TSI definition */
        u8LowPowerScanPeriod = tss_CSSys.LowPowerScanPeriod;
#if (TSS_TSI_VERSION==1) || (TSS_TSI_VERSION==2) 
        psModuleStruct->GENCS |= TSI_GENCS_LPSCNITV(u8LowPowerScanPeriod);   /* Setup TSI Low Power Mode Scan Interval 0 = 1ms - 15 = 500 ms */
#endif
        if (tss_CSSys.SystemConfig.LowPowerEn)
        {
          psModuleStruct->GENCS |= TSI_GENCS_STPE_MASK;     /* TSI Stop Enable while in Low Power Mode (0 = Disable TSI when in LPM, 1 = Allow run of TSI in LPM) */
        } else {
          psModuleStruct->GENCS &= ~TSI_GENCS_STPE_MASK;    /* TSI Stop Enable while in Low Power Mode (0 = Disable TSI when in LPM, 1 = Allow run of TSI in LPM) */
        }
        u8result |= TSS_INIT_STATUS_LOWPOWER_SET;           /* For Indication of state if LowPower was set */
      } else {
        /* Low Power TSI definition */
#if (TSS_TSI_VERSION==1) || (TSS_TSI_VERSION==2)        
    	psModuleStruct->GENCS |= TSI_GENCS_LPSCNITV(0u);   /* Setup TSI Low Power Mode Scan Interval 0 = 1ms - 15 = 500 ms */
#endif
    	psModuleStruct->GENCS &= ~TSI_GENCS_STPE_MASK;    /* TSI Stop Enable while in Low Power Mode (0 = Disable TSI when in LPM, 1 = Allow run of TSI in LPM) */
      }

      return u8result;
    }

    /***************************************************************************//*!
    *
    * @brief  Control function for TSI Pin Enable Settings
    *
    * @param  *psMethodROMDataStruct - Specificcation of ROMDATA Struct
    *         psModuleStruct - Specification of TSI module
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_InitPEN(TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct)
    {
      UINT8 u8result = TSS_INIT_STATUS_OK;
      UINT8 u8ElCounter;
      UINT16 u16Temp;

	  psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK; /* Turn OFF TSI Module if TSI was enabled */
	
      /* PEN Clearing */
      if (tss_CSSys.SystemConfig.ProximityEn || tss_CSSys.SystemConfig.LowPowerEn)
      {
        u16Temp = (1u << ((TSS_TSI_ELECTRODE_ROMDATA *) (tss_acp8ElectrodeROMData[tss_CSSys.LowPowerElectrode]))->tsi_cu32ChannelNum);
        psModuleStruct->PEN &= (TSI_PEN_LPSP_MASK | u16Temp);
      } else {
        for(u8ElCounter = 0u; u8ElCounter < TSS_N_ELECTRODES; u8ElCounter++) /* Find all with the same module */
        {
          if ((TSS_GENERIC_METHOD_ROMDATA*) psMethodROMDataStruct == (TSS_GENERIC_METHOD_ROMDATA *)((TSS_GENERIC_ELECTRODE_ROMDATA *)tss_acp8ElectrodeROMData[u8ElCounter])->gen_cpsMethodROMData)
          {
            /* Disable Standard Electrode */
            if (!(tss_au8ElectrodeEnablers[u8ElCounter >> 3u] & (1u << (u8ElCounter % 8u))))
            {
              if ((psModuleStruct->PEN & (1u << ((TSS_TSI_ELECTRODE_ROMDATA *) (tss_acp8ElectrodeROMData[u8ElCounter]))->tsi_cu32ChannelNum)) != 0u)
              {                
                /* If the Electrode is enabled then disable Electrode */
                psModuleStruct->PEN &= ~(1u << ((TSS_TSI_ELECTRODE_ROMDATA *) (tss_acp8ElectrodeROMData[u8ElCounter]))->tsi_cu32ChannelNum);
              }
            }
          }
        }
      }
      /* PEN Enabling - The loop must be performed twice because one PEN can be assigned to more TSS electrodes */
      for(u8ElCounter = 0u; u8ElCounter < TSS_N_ELECTRODES; u8ElCounter++) /* Find all with the same module */
      {
    	if ((TSS_GENERIC_METHOD_ROMDATA*) psMethodROMDataStruct == (TSS_GENERIC_METHOD_ROMDATA *)((TSS_GENERIC_ELECTRODE_ROMDATA *)tss_acp8ElectrodeROMData[u8ElCounter])->gen_cpsMethodROMData)
        {
            /* Enable Standard Electrode */
            if (tss_au8ElectrodeEnablers[u8ElCounter >> 3u] & (1u << (u8ElCounter % 8u)))
            {
              if ((psModuleStruct->PEN & (1u << ((TSS_TSI_ELECTRODE_ROMDATA *) (tss_acp8ElectrodeROMData[u8ElCounter]))->tsi_cu32ChannelNum)) == 0u)
              {
                /* If the Electrode is disabled then Enable  Electrode */
                psModuleStruct->PEN |= (1u << ((TSS_TSI_ELECTRODE_ROMDATA *) (tss_acp8ElectrodeROMData[u8ElCounter]))->tsi_cu32ChannelNum);
              }
            }
          }
        }
	  
    psModuleStruct->GENCS |= TSI_GENCS_TSIEN_MASK; /* Turn ON TSI Module if TSI was disabled */   
    
	return u8result;
    }

    /***************************************************************************//*!
    *
    * @brief  Control function for TSI Recalibration
    *
    * @param  psModuleStruct - Specification of TSI module
	*         *psMethodRAMDataStruct - Specificcation of RAMDATA Struct
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    #if ((TSS_TSI_EXTCHRG_RANGE != 1) || (TSS_TSI_PS_RANGE != 1) || defined(TSS_ONPROXIMITY_CALLBACK))
    UINT8 TSI_Recalibrate(TSS_TSI_MemMapPtr psModuleStruct, TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct)
    {
      TSI_CALIBRATION FinalTSICalibration;
      TSI_CALIBRATION FinalTSICalibrationBelow;
      TSI_CALIBRATION TempTSICalibration;
      TSI_CALIBRATION OldTSICalibration;
      
      UINT8 u8result = TSS_INIT_STATUS_OK;
      UINT16 u16ElCounter;
      UINT8 u8Counter;
      UINT8 u8TSIPSTemp;
      UINT8 u8TSIExtChrgTemp;
      UINT8 u8CalibrationComplete;
      UINT16 u16CapSampleTemp;
      UINT8 u8Iteration;
      UINT16 u16ResolutionValue;
      UINT8 u8EXTCHRGRange;
      UINT8 u8PSHighLimit;
      UINT16 u16CapSampleAverage;
      UINT8 u8FinalTSICalibrationFound;
      UINT8 u8Found;
      
      /* Save previous TSI Calibration */
      OldTSICalibration.u8TSIPS = (UINT8) ((psModuleStruct->GENCS & TSI_GENCS_PS_MASK) >> TSI_GENCS_PS_SHIFT);
      OldTSICalibration.u8TSIExtChrg = (UINT8) ((psModuleStruct->SCANC & TSI_SCANC_EXTCHRG_MASK) >> TSI_SCANC_EXTCHRG_SHIFT);
      /* Init TSI for Auto calibration */
      psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK; /* Turn OFF TSI Module */
      psModuleStruct->GENCS &= ~TSI_GENCS_TSIIE_MASK; /* Disable Interrupts */
      #if (TSS_TSI_VERSION==1)
        /* Set Default Thresholds on all electrodes */
        for(u16ElCounter = 0u; u16ElCounter < 16u; u16ElCounter++) /* Find all with the same module */
        {
          /* Set Universal Threshold Values for all electrodes */
          psModuleStruct->THRESHOLD[u16ElCounter] = TSI_THRESHOLD_HTHH(TSS_TSI_DEFAULT_HIGH_THRESHOLD) | TSI_THRESHOLD_LTHH(TSS_TSI_DEFAULT_LOW_THRESHOLD);
        }
      #elif (TSS_TSI_VERSION==2) || (TSS_TSI_VERSION==3)
        /* Set Universal Threshold Values for all electrodes */
        psModuleStruct->THRESHOLD = TSI_THRESHOLD_HTHH(TSS_TSI_DEFAULT_HIGH_THRESHOLD ) | TSI_THRESHOLD_LTHH(TSS_TSI_DEFAULT_LOW_THRESHOLD );
      #endif
  
        /* Set Variables */
        if (tss_CSSys.SystemConfig.ProximityEn)
        {
          u16ResolutionValue = TSS_TSI_PROX_RESOLUTION_VALUE;
          u8EXTCHRGRange = TSS_TSI_PROX_EXTCHRG_RANGE;
          u8PSHighLimit = TSS_TSI_PROX_PS_HIGH_LIMIT;        
          u8TSIPSTemp = TSS_TSI_PROX_PS_LOW_LIMIT;
        }else{
          u16ResolutionValue = TSS_TSI_RESOLUTION_VALUE;
          u8EXTCHRGRange = TSS_TSI_EXTCHRG_RANGE;
          u8PSHighLimit = TSS_TSI_PS_HIGH_LIMIT;
          u8TSIPSTemp = TSS_TSI_PS_LOW_LIMIT;
        }
  
        /* Do Autocalibration */
        FinalTSICalibration.u16Distance = 0xFFFFu;
        FinalTSICalibrationBelow.u16Distance = 0xFFFFu;
        u8FinalTSICalibrationFound = 0u;
        do {
          /* Set initial EXTHCRG */
          u8TSIExtChrgTemp = TSS_TSI_EXTCHRG_LOW_LIMIT + (TSS_TSI_EXTCHRG_RANGE / 2u);        
          u8Iteration = 0u;
          TempTSICalibration.u16Distance = 0xFFFFu; 
          u8Found = 0u;
          do {
            /* Increase iteration level */
            u8Iteration += 1u;

            /* Set TSI registers for Single measurement */
            psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK;      /* Disable TSI */
            psModuleStruct->GENCS &= ~TSI_GENCS_PS_MASK;         /* Erase PS */
            psModuleStruct->GENCS |= TSI_GENCS_PS(u8TSIPSTemp);  /* Set Prescaler for Electrode OSC - Set by the user 1 = divide 1, 7 = divide 128 */
            psModuleStruct->SCANC &= ~TSI_SCANC_EXTCHRG_MASK;    /* Erase ExtChrg */
            psModuleStruct->SCANC |= TSI_SCANC_EXTCHRG(u8TSIExtChrgTemp); /* External OSC Charge Current 0= 1uA, 31 = 32uA */
            /* Start Measurement */
            psModuleStruct->GENCS &= ~TSI_GENCS_STM_MASK;  /* Set Scan Trigger Mode (0 = SW Trigger, 1 = Periodical Scan) */
            psModuleStruct->GENCS |= TSI_GENCS_TSIEN_MASK;
            psModuleStruct->GENCS |= TSI_GENCS_SWTS_MASK;
            #ifdef _TSS_TEST
              _TSS_TSIGEN_ON;                                       /* Start generator for test purpose */
            #endif
            do {
            /* Measurement Running */
            } while (!(psModuleStruct->GENCS & TSI_GENCS_EOSF_MASK)); /* If TSI End of Scan Flag is reported*/
            #ifdef _TSS_TEST
              _TSS_TSIGEN_OFF;                                      /* Stop generator */
            #endif
            /* Wait for data ready */
            for(u8Counter = 0u; u8Counter < 20u; u8Counter++)        /* Delay */
            {
              #if defined(__ARMCC_VERSION)
                __nop();
              #else
                asm ("NOP");
              #endif 
            }
            #if (TSS_TSI_VERSION==1)
              /* Erase all Fault Flags for sure */
              psModuleStruct->STATUS = 0xFFFFFFFFu;
            #elif (TSS_TSI_VERSION==2) || (TSS_TSI_VERSION==3)
              psModuleStruct->GENCS |= TSI_GENCS_EXTERF_MASK;
            #endif
            /* Check if all electrodes has proper Counter value */
            u8CalibrationComplete = 1u;
            u16CapSampleAverage = 0u;
            for(u16ElCounter = 0u; u16ElCounter < 16u; u16ElCounter++) /* Go through all enabled pins */
            {
                /* Consider just enabled electrodes */
                if (psModuleStruct->PEN & (1u << u16ElCounter))
                {
                  /* Read TSI Counter */
                #if TSS_KINETIS_MCU   
                  u16CapSampleTemp = (psModuleStruct->tsi_u16Counter[u16ElCounter]);
                #elif TSS_CFM_MCU
                  u16CapSampleTemp = (psModuleStruct->tsi_u16Counter[(u16ElCounter % 2) ? u16ElCounter-1u : u16ElCounter+1u]);   /* Big endian */
                #endif
                
                   if (u16CapSampleTemp < u16ResolutionValue)
                   {
                     u8CalibrationComplete = 0u; /* Capacitance value is small */
                   }
                   if (u16CapSampleAverage == 0u)
                   {
                     u16CapSampleAverage = u16CapSampleTemp;
                   } else {
                     u16CapSampleAverage = (u16CapSampleAverage >> 1u) + (u16CapSampleTemp >> 1u);
                   }
                }
            }

            /* Evaluate Measurement - Reuse of u16ECounter */
            if(u16CapSampleAverage > u16ResolutionValue )
            {
              u16ElCounter = u16CapSampleAverage - u16ResolutionValue;
            } else {
              u16ElCounter = u16ResolutionValue - u16CapSampleAverage;
            }
            
            /* All samples > resolution AND (Avarage > resolution OR already found and tune it) */
            if ((u8CalibrationComplete == 1u ) && ((u16CapSampleAverage > u16ResolutionValue) || (u8Found && (TempTSICalibration.u16Distance >= u16ElCounter)))) 
            {
              TempTSICalibration.u8TSIExtChrg = u8TSIExtChrgTemp;
              TempTSICalibration.u8TSIPS = u8TSIPSTemp;
              TempTSICalibration.u16Distance = u16ElCounter;
              u8Found++; /* Match for set PS found */ 
            } else if (TempTSICalibration.u16Distance >= u16ElCounter && (u8Found ==0))  
            {
              TempTSICalibration.u8TSIExtChrg = u8TSIExtChrgTemp;
              TempTSICalibration.u8TSIPS = u8TSIPSTemp;
              TempTSICalibration.u16Distance = u16ElCounter;
            }
            /* Change ExtCharge within the interval */
            if(u8CalibrationComplete == 1u)
            {
              u8TSIExtChrgTemp += ((u8EXTCHRGRange / 2u) >> u8Iteration);
            }
            else
            {
              u8TSIExtChrgTemp -= ((u8EXTCHRGRange / 2u) >> u8Iteration);
            }
          } while (((u8EXTCHRGRange / 2u) >> u8Iteration) > 0u);           
          /* The value only if distance is lower and was found with sufficient resolution */
          if ((FinalTSICalibration.u16Distance >= TempTSICalibration.u16Distance) && (u8Found > 0))
          {
            FinalTSICalibration.u8TSIPS = TempTSICalibration.u8TSIPS;
            FinalTSICalibration.u8TSIExtChrg = TempTSICalibration.u8TSIExtChrg;
            FinalTSICalibration.u16Distance = TempTSICalibration.u16Distance;
            u8FinalTSICalibrationFound++;
          } else if ((FinalTSICalibrationBelow.u16Distance >= TempTSICalibration.u16Distance) && (u8FinalTSICalibrationFound == 0))
          {
            /* Calibration not sufficient to the set resolution */
            FinalTSICalibrationBelow.u8TSIPS = TempTSICalibration.u8TSIPS;
            FinalTSICalibrationBelow.u8TSIExtChrg = TempTSICalibration.u8TSIExtChrg;
            FinalTSICalibrationBelow.u16Distance = TempTSICalibration.u16Distance;
          }
            
          u8TSIPSTemp++; /* Increment PS current */
        } while (u8TSIPSTemp < (u8PSHighLimit + 1u)); 
  
        /* Check if searching was succesful */
        if (u8FinalTSICalibrationFound)
        {
          psMethodRAMDataStruct->tsi_au16Resolution = u16ResolutionValue;
        } else {
          FinalTSICalibration.u8TSIPS = FinalTSICalibrationBelow.u8TSIPS;
          FinalTSICalibration.u8TSIExtChrg = FinalTSICalibrationBelow.u8TSIExtChrg;
          /* Reuse of u8Counter & u16ElCounter */
          u8Counter = 0u;  
          u16ElCounter = u16ResolutionValue - FinalTSICalibrationBelow.u16Distance;
          /* Determine TSS Resolution (highest bit set) */
          while (u16ElCounter >> u8Counter)
          {
            u8Counter++;
          }
          /* Store the present resolution value */    
          psMethodRAMDataStruct->tsi_au16Resolution = (1u << (u8Counter - 1u));
        }
        /* Set Final Found values */
        psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK;   /* Disable TSI */
        psModuleStruct->GENCS &= ~TSI_GENCS_PS_MASK;      /* Erase PS */
        psModuleStruct->GENCS |= TSI_GENCS_PS(FinalTSICalibration.u8TSIPS);       /* Set Prescaler for Electrode OSC - Set by the user 1 = divide 1, 7 = divide 128 */
        psModuleStruct->SCANC &= ~TSI_SCANC_EXTCHRG_MASK; /* Erase ExtChrg */
        psModuleStruct->SCANC |= TSI_SCANC_EXTCHRG(FinalTSICalibration.u8TSIExtChrg);  /* External OSC Charge Current 0= 1uA, 31 = 32uA */
        /* Save Value for Proximity function */
      #ifdef TSS_ONPROXIMITY_CALLBACK
        if (tss_CSSys.SystemConfig.ProximityEn)
        {
          tss_u16CapSample = FinalTSICalibration.u16Distance + u16ResolutionValue;
        }
      #endif  
        /* Indication of changed configuration */
        if ((OldTSICalibration.u8TSIPS != FinalTSICalibration.u8TSIPS) || (OldTSICalibration.u8TSIExtChrg != FinalTSICalibration.u8TSIExtChrg))
        {
          /* Save result */  
          u8result |= TSS_INIT_STATUS_CALIBRATION_CHANGED;
        }

        return u8result;
    }
    #else
    UINT8 TSI_Recalibrate(TSS_TSI_MemMapPtr psModuleStruct, TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct)
    {
         UINT8 u8result = TSS_INIT_STATUS_OK;
        
         /* Set Final Found values */
         psModuleStruct->STATUS = 0xFFFFFFFFu;
         psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK;   /* Disable TSI */
         psModuleStruct->GENCS &= ~TSI_GENCS_PS_MASK;      /* Erase PS */
         psModuleStruct->SCANC &= ~TSI_SCANC_EXTCHRG_MASK; /* Erase ExtChrg */
         /* Set configuration directly */
         psModuleStruct->GENCS |= TSI_GENCS_PS(TSS_TSI_PS_HIGH_LIMIT);       /* Set Prescaler for Electrode OSC - Set by the user 1 = divide 1, 7 = divide 128 */
         psModuleStruct->SCANC |= TSI_SCANC_EXTCHRG(TSS_TSI_EXTCHRG_HIGH_LIMIT);  /* External OSC Charge Current 0= 1uA, 31 = 32uA */
         
         psMethodRAMDataStruct->tsi_au16Resolution = TSS_TSI_RESOLUTION_VALUE;  /* Store the resolution value */ 
         
         return u8result;
    }
    #endif

    /***************************************************************************//*!
    *
    * @brief  Control function for TSI Thresholds Settings
    *
    * @param  *psMethodROMDataStruct - Specificcation of ROMDATA Struct
    *         psModuleStruct - Specification of TSI module
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_InitThresholds(TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct)
    {
      UINT8 u8result = TSS_INIT_STATUS_OK;
      UINT8 u8LowPowerEl;
      UINT8 u8Counter;
      UINT16 u16CapSampleTemp;
      UINT8 u8LowPowerElectrodeSensitivity;
      UINT8 u8ChannelNum;

      psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK; /* Turn OFF TSI Module */
      psModuleStruct->GENCS &= ~TSI_GENCS_TSIIE_MASK; /* Disable Interrupts */
      #if (TSS_TSI_VERSION == 1)
        /*** Set Default Low Power Thresholds for all electrodes within module***/
        for(u8Counter = 0u; u8Counter < 16u; u8Counter++) /* Find all within the same module */
        {
          /* Set Universal Threshold Values for all electrodes */
          psModuleStruct->THRESHOLD[u8Counter] = TSI_THRESHOLD_HTHH(TSS_TSI_DEFAULT_HIGH_THRESHOLD) | TSI_THRESHOLD_LTHH(TSS_TSI_DEFAULT_LOW_THRESHOLD);
        }
      #elif (TSS_TSI_VERSION == 2) || (TSS_TSI_VERSION==3)
        /* Set Universal Threshold Values for all electrodes */
        psModuleStruct->THRESHOLD = TSI_THRESHOLD_HTHH(TSS_TSI_DEFAULT_HIGH_THRESHOLD ) | TSI_THRESHOLD_LTHH(TSS_TSI_DEFAULT_LOW_THRESHOLD );
      #endif
      /* If Module is selected for Low Power Control do following */
      if (psMethodROMDataStruct->tsi_u8LowPowerControlSource == 1u) /* This TSI module is Low Power Control source */
      {
        u8LowPowerEl = tss_CSSys.LowPowerElectrode;
        /* Check if Low Power Electrode is not out of range */        
        if (u8LowPowerEl < TSS_N_ELECTRODES)/* This electrode is selected as source for Low Power Control */
        {
          /* Check if low power electrode is member of the module */
          if ((TSS_GENERIC_METHOD_ROMDATA *) psMethodROMDataStruct == (TSS_GENERIC_METHOD_ROMDATA *)((TSS_GENERIC_ELECTRODE_ROMDATA *)tss_acp8ElectrodeROMData[u8LowPowerEl])->gen_cpsMethodROMData)
          {
            /* Get Channel Num */
            u8ChannelNum = (UINT8) (((TSS_TSI_ELECTRODE_ROMDATA *) (tss_acp8ElectrodeROMData[u8LowPowerEl]))->tsi_cu32ChannelNum);
            /* Check if PEN is enabled */                                      
            if (psModuleStruct->PEN & (1u << u8ChannelNum))
            {
              /******** Low Power Threshold Settings *********/
              /* Init TSI registers for measurement */
              psModuleStruct->GENCS &= ~TSI_GENCS_STM_MASK;  /* Set Scan Trigger Mode (0 = SW Trigger, 1 = Periodical Scan) */
              psModuleStruct->GENCS |= TSI_GENCS_TSIEN_MASK;
              psModuleStruct->GENCS |= TSI_GENCS_SWTS_MASK;
              #ifdef _TSS_TEST
                _TSS_TSIGEN_ON;                                      /* Start generator for test purpose */
              #endif
              do {
              /* Measurement Running */
              } while (!(psModuleStruct->GENCS & TSI_GENCS_EOSF_MASK)); /* If TSI End of Scan Flag is reported*/
              #ifdef _TSS_TEST
                _TSS_TSIGEN_OFF;                                    /* Stop generator */
              #endif
              /* Wait for data ready */
              for(u8Counter = 0u; u8Counter < 20u; u8Counter++) /* Delay */
              {
                #if defined(__ARMCC_VERSION)
                  __nop();
                #else
                  asm ("NOP");
                #endif
              }
              #if (TSS_TSI_VERSION == 1)
                /* Erase all Fault Flags for sure */
                psModuleStruct->STATUS = 0xFFFFFFFFu;
              #elif (TSS_TSI_VERSION == 2) || (TSS_TSI_VERSION == 3)
                psModuleStruct->GENCS |= TSI_GENCS_EXTERF_MASK;
              #endif
              /* Read TSI Counter */
              #if TSS_KINETIS_MCU
                u16CapSampleTemp = (psModuleStruct->tsi_u16Counter[u8ChannelNum]);
              #elif TSS_CFM_MCU
                u16CapSampleTemp = (psModuleStruct->tsi_u16Counter[(u8ChannelNum % 2) ? u8ChannelNum-1u : u8ChannelNum+1u]); /* Big endian */
              #endif
              /* Calculation of Threshold values */
              u8LowPowerElectrodeSensitivity = tss_CSSys.LowPowerElectrodeSensitivity;
              #if (TSS_TSI_VERSION == 1)
                /* Set Threshold for Low Power Wake up */
                psModuleStruct->THRESHOLD[u8ChannelNum] = TSI_THRESHOLD_HTHH(u16CapSampleTemp + u8LowPowerElectrodeSensitivity) | TSI_THRESHOLD_LTHH(TSS_TSI_DEFAULT_LOW_THRESHOLD);
              #elif (TSS_TSI_VERSION == 2) || (TSS_TSI_VERSION == 3)
                psModuleStruct->THRESHOLD = TSI_THRESHOLD_HTHH(u16CapSampleTemp + u8LowPowerElectrodeSensitivity) | TSI_THRESHOLD_LTHH(TSS_TSI_DEFAULT_LOW_THRESHOLD);
              #endif
              /*** Set Active Electrode for Low Power Mode ***/
              psModuleStruct->PEN &= ~TSI_PEN_LPSP_MASK;
              psModuleStruct->PEN |= TSI_PEN_LPSP(u8ChannelNum);
              u8result |= TSS_INIT_STATUS_LOWPOWER_ELEC_SET; /* For Indication of state if LowPower Electrode was found */
            }
          }
        }
      }

      return u8result;
    }

    /***************************************************************************//*!
    *
    * @brief  Control function for TSI Trigger Settings
    *
    * @param  *psMethodROMDataStruct - Specificcation of ROMDATA Struct
    *         psModuleStruct - Specification of TSI module
    *         *psMethodRAMDataStruct - Specificcation of RAMDATA Struct
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_InitTrigger(TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct, TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct)
    {
      UINT8 u8result = TSS_INIT_STATUS_OK;
      UINT8 u8AutoTriggerModuloValue;
      #if TSS_KINETIS_MCU
        NVIC_MemMapPtr psNVICStruct = NVIC_BASE_PTR;
      #endif

      psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK; /* Turn OFF TSI Module*/;
      psModuleStruct->SCANC &= ~TSI_SCANC_SMOD_MASK;  /* Erase SMOD */
      #if (TSS_TSI_VERSION == 1)
        /* Erase all Fault Flags for sure */
        psModuleStruct->STATUS = 0xFFFFFFFFu;
      #elif (TSS_TSI_VERSION == 2) || (TSS_TSI_VERSION == 3)
        psModuleStruct->GENCS |= TSI_GENCS_EXTERF_MASK;
      #endif
      /* Trigger Setting */
      if ((psMethodROMDataStruct->tsi_u8TriggerSource == 1u) && (tss_CSSys.SystemTrigger.TriggerMode == TSS_TRIGGER_MODE_AUTO)) /* This TSI module is Trigger source & Auto mode*/
      {
        /* This TSI module is Trigger source & Auto mode*/
        /* Active Mode Periodic Scan */
        u8AutoTriggerModuloValue = tss_CSSys.AutoTriggerModuloValue;
        psModuleStruct->SCANC |= TSI_SCANC_SMOD(u8AutoTriggerModuloValue); /* Active mode periodic scan period module 0 = Continue scan, Other = scan module */
        psModuleStruct->GENCS |= TSI_GENCS_STM_MASK;                       /* Set Scan Trigger Mode (0 = SW Trigger, 1 = Periodical Scan) */
        /* Indication that AutoTrigger was set correctly */
        u8result |= TSS_INIT_STATUS_AUTOTRIGGER_SET;
      } else { /* Other & ALWAYS & SW mode */
        /* Active Mode Periodic Scan */
        psModuleStruct->SCANC |= TSI_SCANC_SMOD(0u);      /* Active mode periodic scan period module 0 = Continue scan, Other = scan module */
        psModuleStruct->GENCS &= ~TSI_GENCS_STM_MASK;    /* Set Scan Trigger Mode (0 = SW Trigger, 1 = Periodical Scan) */
        u8result |= TSS_INIT_STATUS_TRIGGER_SET;          
      }
      /* Enable EOSF interrupt */
      psModuleStruct->GENCS &= ~TSI_GENCS_ERIE_MASK;  /* Error (Short&Overrun) Interrupt Enable (0 = disabled, 1 = enabled) */
      psModuleStruct->GENCS |= TSI_GENCS_ESOR_MASK;   /* End-of-Scan|Out-of-Range Interrupt Selection (0 = Out-of-Range allow, 1 = End-of-Scan allow) */
      psModuleStruct->GENCS |= TSI_GENCS_TSIIE_MASK;  /* TSI Interrupt Enable (0 = disabled, 1 = enabled) */
      #if TSS_KINETIS_MCU
        /* Enable TSI Interrupt */
        psNVICStruct->ISER[psMethodROMDataStruct->tsi_u8ModuleIRQNum >> 5u] = (1u << (psMethodROMDataStruct->tsi_u8ModuleIRQNum % 32u));
      #endif
      psMethodRAMDataStruct->tsi_eEndOfScanState = TSI_EOSF_STATE_NONE; /* Reset EndOfScanState */

      /* Setup Low Power */
      if ((tss_CSSys.SystemConfig.LowPowerEn) && (psMethodROMDataStruct->tsi_u8LowPowerControlSource == 1u))
      {
        /* Set periodic measurement mode */
        psModuleStruct->GENCS |= TSI_GENCS_STM_MASK;    /* Set Scan Trigger Mode (0 = SW Trigger, 1 = Periodical Scan) */
        /* Enable EOSF interrupt */
        psModuleStruct->GENCS &= ~TSI_GENCS_ERIE_MASK;  /* Error (Short&Overrun) Interrupt Enable (0 = disabled, 1 = enabled) */
        psModuleStruct->GENCS &= ~TSI_GENCS_ESOR_MASK;  /* Set Out of Range interrupt (0 = Out-of-Range allow, 1 = End-of-Scan allow) */
        psModuleStruct->GENCS |= TSI_GENCS_TSIIE_MASK;  /* TSI Interrupt Disable (0 = disabled, 1 = enabled) */
        #if TSS_KINETIS_MCU
          /* Enable TSI Interrupt */
          psNVICStruct->ISER[psMethodROMDataStruct->tsi_u8ModuleIRQNum >> 5u] = (1u << (psMethodROMDataStruct->tsi_u8ModuleIRQNum % 32u));
        #endif
        /* TSI enable and start to periodic measurement */
        psModuleStruct->GENCS |= TSI_GENCS_TSIEN_MASK;  /* TSI Enable (0 = disabled, 1 = enabled) */
        /* Indication that LowPower was set correctly */
        u8result |= TSS_INIT_STATUS_LOWPOWER_SET;       /* For Indication of state if LowPower was set */
        u8result &= ~TSS_INIT_STATUS_TRIGGER_SET;       /* Remove status that Trigger was set correctly */
        u8result &= ~TSS_INIT_STATUS_AUTOTRIGGER_SET;   /* Remove status that Auto Trigger was set correctly */
      }

      return u8result;
    }

    /***************************************************************************//*!
    *
    * @brief  Initializes the modules for the sensing of the electrodes
    *
    * @param  UINT8 u8ElNum - Processed Electrode Number
    *         UINT8 u8Command - Command intended to process
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_MethodControl(UINT8 u8ElNum, UINT8 u8Command)
    {
        UINT8 u8result = TSS_INIT_STATUS_OK;
        TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct;
        TSS_TSI_ELECTRODE_ROMDATA *psElectrodeROMDataStruct;
        TSS_TSI_MemMapPtr psModuleStruct;
        TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct;

        /* Pointers Decoding */
        psElectrodeROMDataStruct = (TSS_TSI_ELECTRODE_ROMDATA *) (tss_acp8ElectrodeROMData[u8ElNum]);
        psMethodROMDataStruct = (TSS_TSI_METHOD_ROMDATA *) (psElectrodeROMDataStruct->tsi_cpsu32MethodROMData);
        psModuleStruct = (TSS_TSI_MemMapPtr) (psMethodROMDataStruct->tsi_cpsu32Module);
        psMethodRAMDataStruct = (TSS_TSI_METHOD_RAMDATA *) (psElectrodeROMDataStruct->tsi_u8MethodRAMData);

        /************* Do TSI Init *******************/
        if (u8Command == TSS_INIT_COMMAND_INIT_MODULES)
        {
          u8result |= TSI_InitModule(psModuleStruct);
          u8result |= TSI_SetNSamples(psModuleStruct);
          u8result |= TSI_InitLowPower(psMethodROMDataStruct, psModuleStruct);
          u8result |= TSI_InitPEN(psMethodROMDataStruct, psModuleStruct);
          u8result |= TSI_Recalibrate(psModuleStruct, psMethodRAMDataStruct);
          u8result |= TSI_InitThresholds(psMethodROMDataStruct, psModuleStruct);
          u8result |= TSI_InitTrigger(psMethodROMDataStruct, psModuleStruct, psMethodRAMDataStruct);
        }
        /************* Set NSamples ***************/
        else if (u8Command == TSS_INIT_COMMAND_SET_NSAMPLES)
        {
          u8result |= TSI_SetNSamples(psModuleStruct);
          u8result |= TSI_Recalibrate(psModuleStruct, psMethodRAMDataStruct);
          u8result |= TSI_InitThresholds(psMethodROMDataStruct, psModuleStruct);
          u8result |= TSI_InitTrigger(psMethodROMDataStruct, psModuleStruct, psMethodRAMDataStruct);
        }
        /************ Low Power Init *************/
        else if (u8Command == TSS_INIT_COMMAND_INIT_LOWPOWER)
        {
          u8result |= TSI_InitLowPower(psMethodROMDataStruct, psModuleStruct);
          u8result |= TSI_InitThresholds(psMethodROMDataStruct, psModuleStruct);
          u8result |= TSI_InitTrigger(psMethodROMDataStruct, psModuleStruct, psMethodRAMDataStruct);
        }
        /************* Goto Low Power ************/
        else if (u8Command == TSS_INIT_COMMAND_GOTO_LOWPOWER)
        {
          u8result |= TSI_InitLowPower(psMethodROMDataStruct, psModuleStruct);
          u8result |= TSI_InitTrigger(psMethodROMDataStruct, psModuleStruct, psMethodRAMDataStruct);
        }
        /*************** Do Auto calibration setting of TSI EXTCHRG and TSI PS **************/
        else if (u8Command == TSS_INIT_COMMAND_RECALIBRATE)
        {
          u8result |= TSI_Recalibrate(psModuleStruct, psMethodRAMDataStruct);
          u8result |= TSI_InitThresholds(psMethodROMDataStruct, psModuleStruct);
          u8result |= TSI_InitTrigger(psMethodROMDataStruct, psModuleStruct, psMethodRAMDataStruct);
        }
        /************ Electrode Enablers & Low Power Thresholds & Low Power Electrode Specification *************/
        else if (u8Command == TSS_INIT_COMMAND_ENABLE_ELECTRODES)
        {
          u8result |= TSI_InitPEN(psMethodROMDataStruct, psModuleStruct);
        }
        /************* Triggering Init ************/
        else if (u8Command == TSS_INIT_COMMAND_INIT_TRIGGER)
        {
          u8result |= TSI_InitTrigger(psMethodROMDataStruct, psModuleStruct, psMethodRAMDataStruct);
        }
        /************* SWTrigger ************/
        if (u8Command == TSS_INIT_COMMAND_SW_TRIGGER)
        {
            psMethodRAMDataStruct->tsi_eEndOfScanState = TSI_EOSF_STATE_NONE; /* Reset EndOfScanState */
            psModuleStruct->GENCS |= TSI_GENCS_SWTS_MASK; /* Toggle SW Trigger */
            u8result |= TSS_INIT_STATUS_TRIGGER_SET;
            #ifdef _TSS_TEST
              _TSS_TSIGEN_ON;                                 /* Start generator for test purpose */
            #endif
          }

      /* Exit */

      return u8result;
    }

    /***************************************************************************//*!
    *
    * @brief  Reads TSI capacitance counter and returns a status code
    *
    * @param  *psElectrodeROMDataStruct - Specificcation of electrode ROMDATA Struct
    *         psModuleStruct - Specification of TSI module
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_ReadCounter(TSS_TSI_ELECTRODE_ROMDATA *psElectrodeROMDataStruct, TSS_TSI_MemMapPtr psModuleStruct, TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct)
    {
      UINT8 u8result;

      #if (TSS_TSI_VERSION == 1)
      /* Read Status register */
      u8result = (UINT8) ((psModuleStruct->STATUS & ((1u << psElectrodeROMDataStruct->tsi_cu32ChannelNum) << 16u)) >> (psElectrodeROMDataStruct->tsi_cu32ChannelNum + 16u));
      #elif (TSS_TSI_VERSION == 2) || (TSS_TSI_VERSION == 3)
       u8result = (UINT8) (psModuleStruct->GENCS & TSI_GENCS_EXTERF_MASK);
      #endif
      /* Evaluate Status */
      if (u8result != 0u)
      {
        #if (TSS_TSI_VERSION == 1)
        psModuleStruct->STATUS |= ((1u << psElectrodeROMDataStruct->tsi_cu32ChannelNum) << 16u); /* Erase Fault Flag */
        #elif (TSS_TSI_VERSION == 2) || (TSS_TSI_VERSION == 3)
        psModuleStruct->GENCS |= TSI_GENCS_EXTERF_MASK;
        #endif
        u8result = TSS_SAMPLE_ERROR_CHARGE_TIMEOUT;
      }
      else
      {
        /* Read TSI Counter */
        #if TSS_KINETIS_MCU                
          tss_u16CapSample = (psModuleStruct->tsi_u16Counter[psElectrodeROMDataStruct->tsi_cu32ChannelNum]); /* Read TSI Counter */
        #elif TSS_CFM_MCU
          tss_u16CapSample = (psModuleStruct->tsi_u16Counter[(psElectrodeROMDataStruct->tsi_cu32ChannelNum % 2u) ? psElectrodeROMDataStruct->tsi_cu32ChannelNum-1u : psElectrodeROMDataStruct->tsi_cu32ChannelNum+1u]); /* Read TSI Counter, Big endian*/
        #endif
        /* Evaluation of the Measured Value */
        if (tss_u16CapSample > TSS_TSI_CAP_HIGH_LIMIT(psMethodRAMDataStruct->tsi_au16Resolution))
        {
          u8result = TSS_SAMPLE_ERROR_CHARGE_TIMEOUT;    /* Too High Capacity is detected */
        } else if (tss_u16CapSample > TSS_TSI_RECALIBRATION_HIGH_THRESHOLD(psMethodRAMDataStruct->tsi_au16Resolution))
        {
          u8result = TSS_SAMPLE_RECALIB_REQUEST_HICAP;   /* Re-calibration is needed */
        }else if (tss_u16CapSample < TSS_TSI_CAP_LOW_LIMIT(psMethodRAMDataStruct->tsi_au16Resolution)) 
        {  
          u8result = TSS_SAMPLE_ERROR_SMALL_CAP;         /* Too Low Capacity is detected */
        } 
        else if (tss_u16CapSample < TSS_TSI_RECALIBRATION_LOW_THRESHOLD(psMethodRAMDataStruct->tsi_au16Resolution)) 
        {  
          u8result = TSS_SAMPLE_RECALIB_REQUEST_LOCAP;   /* Re-calibration is needed */
        } else {
          u8result = TSS_SAMPLE_STATUS_OK;
        }
      }

      return u8result;
    }

    /***************************************************************************//*!
    *
    * @brief  Performs a valid reading of one electrode stores the timer values
    *         and returns a status code
    *
    * @param  u8ElecNum Electrode number to be scanned
    *         u8Command Requested command
    *
    * @return Status Code
    *
    * @remarks
    *
    ****************************************************************************/
    UINT8 TSI_SampleElectrode(UINT8 u8ElecNum, UINT8 u8Command)
    {
      UINT8 u8ElectrodeStatus;
      UINT8 u8ElCounter;

      TSS_TSI_METHOD_ROMDATA *psMethodROMDataStruct;
      TSS_TSI_ELECTRODE_ROMDATA *psElectrodeROMDataStruct;
      TSS_TSI_METHOD_RAMDATA *psMethodRAMDataStruct;
      TSS_TSI_MemMapPtr psModuleStruct;

      /* Pointers decoding */
      psElectrodeROMDataStruct = (TSS_TSI_ELECTRODE_ROMDATA *) (tss_acp8ElectrodeROMData[u8ElecNum]);
      psMethodROMDataStruct = (TSS_TSI_METHOD_ROMDATA *) (psElectrodeROMDataStruct->tsi_cpsu32MethodROMData);
      psModuleStruct = (TSS_TSI_MemMapPtr) (psMethodROMDataStruct->tsi_cpsu32Module);
      psMethodRAMDataStruct = (TSS_TSI_METHOD_RAMDATA *) (psElectrodeROMDataStruct->tsi_u8MethodRAMData);

      /* Module Control */
      if (u8Command == TSS_SAMPLE_COMMAND_RESTART)
      {
        /* Do TSI init */
        if (!(psModuleStruct->GENCS & TSI_GENCS_TSIEN_MASK)) /* If TSI is disabled then enable */
        {
          psModuleStruct->GENCS |= TSI_GENCS_TSIEN_MASK;
        }
        /* Evaluate status */ 
        if ( tss_CSSys.SystemTrigger.TriggerMode == TSS_TRIGGER_MODE_AUTO)
        {
          if (psMethodRAMDataStruct->tsi_eEndOfScanState == TSI_EOSF_STATE_ERROR)
          {
            u8ElectrodeStatus = TSS_SAMPLE_ERROR_SMALL_TRIGGER_PERIOD; /* Small TriggerModuloValue */
            psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK;           /* Disable whole TSS due triggering crash */
            #ifdef _TSS_TEST
               _TSS_TSIGEN_OFF;           /* Stop generator for test purpose */
            #endif
          } else {
            u8ElectrodeStatus = TSS_SAMPLE_STATUS_PROCESSING;
          }
          psMethodRAMDataStruct->tsi_eEndOfScanState = TSI_EOSF_STATE_NONE; /* Reset EndOfScanState */
        } else { /* If Always & SW Mode */
          /* If Always Mode restart TSI measurement by SW Trigger Toggle */
          if ( tss_CSSys.SystemTrigger.TriggerMode == TSS_TRIGGER_MODE_ALWAYS)
          {
            /* TSI scanning is in progress or one TSI measurement done */
            if (( psModuleStruct->GENCS & TSI_GENCS_SCNIP_MASK ) || (psMethodRAMDataStruct->tsi_eEndOfScanState == TSI_EOSF_STATE_REGULAR))
            {
              /* Nothing */
            } else {
              psMethodRAMDataStruct->tsi_eEndOfScanState = TSI_EOSF_STATE_NONE; /* Reset EndOfScanState */
              psModuleStruct->GENCS |= TSI_GENCS_SWTS_MASK;  /* Toggle SW Trigger */
              #ifdef _TSS_TEST
                _TSS_TSIGEN_ON;          /* Start generator for test purpose */
              #endif
            }
          }
          u8ElectrodeStatus = TSS_SAMPLE_STATUS_PROCESSING;
        }
      }
      else if (u8Command == TSS_SAMPLE_COMMAND_PROCESS)
      {
        /* If TSI is disabled then enable */
        if (!(psModuleStruct->GENCS & TSI_GENCS_TSIEN_MASK))
        {
          psModuleStruct->GENCS |= TSI_GENCS_TSIEN_MASK;
        }
        /* Evaluate status */
        if ( tss_CSSys.SystemTrigger.TriggerMode == TSS_TRIGGER_MODE_AUTO)
        {
          #ifdef _TSS_TEST
            _TSS_TSIGEN_ON;              /* Start generator for test purpose */
          #endif
          if ((psMethodRAMDataStruct->tsi_eEndOfScanState == TSI_EOSF_STATE_NONE) || ((psMethodRAMDataStruct->tsi_eEndOfScanState == TSI_EOSF_STATE_REGULAR) && (!(psModuleStruct->GENCS & TSI_GENCS_SCNIP_MASK))))
          {
            u8ElectrodeStatus = TSS_SAMPLE_STATUS_PROCESSING;
          } else if ( (psMethodRAMDataStruct->tsi_eEndOfScanState == TSI_EOSF_STATE_EXCESS) || ((psMethodRAMDataStruct->tsi_eEndOfScanState == TSI_EOSF_STATE_REGULAR) && (psModuleStruct->GENCS & TSI_GENCS_SCNIP_MASK)))
          {
            /* Read TSI Counter */
            u8ElectrodeStatus = TSI_ReadCounter(psElectrodeROMDataStruct, psModuleStruct, psMethodRAMDataStruct);
          }
          else
          {
            u8ElectrodeStatus = TSS_SAMPLE_ERROR_SMALL_TRIGGER_PERIOD; /* Small TriggerModuloValue */
            psModuleStruct->GENCS &= ~TSI_GENCS_TSIEN_MASK;            /* Disable whole TSS due triggering crash */
            psMethodRAMDataStruct->tsi_eEndOfScanState = TSI_EOSF_STATE_NONE; /* Reset EndOfScanState */
            #ifdef _TSS_TEST
              _TSS_TSIGEN_OFF;           /* Stop generator for test purpose */
            #endif
          }
        } else {  /* Always & SW Mode */
          if (psModuleStruct->GENCS & TSI_GENCS_SCNIP_MASK) /* TSI scanning is in progress */
          {
            u8ElectrodeStatus = TSS_SAMPLE_STATUS_PROCESSING;
          }
          else
          {
            /* If TSI End of Scan Flag is reported */
            if (psMethodRAMDataStruct->tsi_eEndOfScanState >= TSI_EOSF_STATE_REGULAR)
            {
              psMethodRAMDataStruct->tsi_eEndOfScanState = TSI_EOSF_STATE_PROCESS;
              #ifdef _TSS_TEST
                _TSS_TSIGEN_OFF;         /* Stop generator */
              #endif
              /* Read TSI Counter */
              u8ElectrodeStatus = TSI_ReadCounter(psElectrodeROMDataStruct, psModuleStruct, psMethodRAMDataStruct);
            }
            else
            {
              /* Toggle TSI SW Trigger again if process was interrupted for sure */
              if (tss_CSSys.SystemTrigger.TriggerMode == TSS_TRIGGER_MODE_ALWAYS)
              {
                psMethodRAMDataStruct->tsi_eEndOfScanState = TSI_EOSF_STATE_NONE; /* Reset EndOfScanState */
                psModuleStruct->GENCS |= TSI_GENCS_SWTS_MASK;  
              }
              #ifdef _TSS_TEST
                _TSS_TSIGEN_ON;          /* Start generator for test purpose */
              #endif
              u8ElectrodeStatus = TSS_SAMPLE_STATUS_PROCESSING;
            }
          }
        }
      }
      else if (u8Command == TSS_SAMPLE_COMMAND_GET_NEXT_ELECTRODE)
      {
        /* Find the next electrode within the electrode module */
        u8ElCounter = u8ElecNum;
        do {
          if (u8ElCounter < (TSS_N_ELECTRODES - 1u))
          {
            u8ElCounter++;
          } else {
            u8ElCounter = 0u;
          }
        } while ((TSS_GENERIC_METHOD_ROMDATA*) psMethodROMDataStruct != (TSS_GENERIC_METHOD_ROMDATA *)((TSS_GENERIC_ELECTRODE_ROMDATA *)tss_acp8ElectrodeROMData[u8ElCounter])->gen_cpsMethodROMData);
        /* Return found electrode number */
        u8ElectrodeStatus = u8ElCounter;

      } else if (u8Command == TSS_SAMPLE_COMMAND_RECALIB)
      {
        u8ElectrodeStatus = TSI_MethodControl(u8ElecNum, TSS_INIT_COMMAND_RECALIBRATE);

        if (u8ElectrodeStatus & TSS_INIT_ERROR_RECALIB_FAULT)
        {
          /* Fault happened, so disable actual electrode */
          u8ElectrodeStatus = TSS_SAMPLE_ERROR_CHARGE_TIMEOUT;
        } else if (u8ElectrodeStatus & TSS_INIT_STATUS_CALIBRATION_CHANGED)
        {
          /* Calibration changed */
          u8ElectrodeStatus = TSS_SAMPLE_STATUS_CALIBRATION_CHANGED;
        } else
        {
          /* Old calibration was correct */
          u8ElectrodeStatus = TSS_SAMPLE_STATUS_OK;
        }

      } else if (u8Command == TSS_SAMPLE_COMMAND_ENABLE_ELECTRODE)
      {
        u8ElectrodeStatus = TSI_MethodControl(u8ElecNum, TSS_INIT_COMMAND_ENABLE_ELECTRODES);

        u8ElectrodeStatus = TSS_SAMPLE_STATUS_OK;
      }

      return u8ElectrodeStatus;   /* Return status code */

    }

    /***************************************************************************//*!
    *
    * @brief  TSI ISR routines
    *
    * @remarks
    *
    ****************************************************************************/
    #if TSS_DETECT_MODULE(TSI)
      #if TSS_KINETIS_MCU
        #if TSS_ENABLE_DIAGNOSTIC_MESSAGES
          #warning TSS - Please assign ISR function TSS_TSIIsr to vector INT_TSI
        #endif
      #elif TSS_CFM_MCU
        #if TSS_ENABLE_DIAGNOSTIC_MESSAGES
          #warning TSS - Please assign ISR function TSS_TSIIsr to vector Vtsi
        #endif
        #if !TSS_USE_MQX
          interrupt
        #endif
      #endif
      void TSS_TSIIsr(
        #if TSS_USE_MQX
          void *_isrParameter
        #else
          void
        #endif
        )
      {
        UINT16 u16temp;
        
        ((TSS_TSI_MemMapPtr) (TSS_TSI_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_TSIEN_MASK; /* Due to 0M33Z maskset (unfreeze after restart) */
        if (tss_CSSys.SystemConfig.LowPowerEn)
        {
          #if (TSS_TSI_VERSION==1)
          ((TSS_TSI_MemMapPtr) (TSS_TSI_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->STATUS = 0xFFFFFFFFu;  /* Clear OUTFRG Status Flag */
          #endif            
          ((TSS_TSI_MemMapPtr) (TSS_TSI_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_OUTRGF_MASK; /* Clear OUTFRG Flag */
          ((TSS_TSI_MemMapPtr) (TSS_TSI_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS &= ~TSI_GENCS_TSIIE_MASK; /* Disable TSI Interrupt */
          /* Disables LowPower Wake Up */
          u16temp = TSS_GetSystemConfig(System_SystemConfig_Register);
          (void)TSS_SetSystemConfig(System_SystemConfig_Register,(u16temp & ~TSS_LOWPOWER_EN_MASK));  
        } else {
          ((TSS_TSI_MemMapPtr) (TSS_TSI_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_EOSF_MASK;  /* Clear Flag */
          #ifdef _TSS_TEST
            _TSS_TSIGEN_OFF;         /* Stop generator */
          #endif
          if (TSS_TSI_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState != TSI_EOSF_STATE_ERROR)
          {
            /* Increment tsi_u8EndOfScanState */
            TSS_TSI_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState = (TSS_TSI_EOSF_STATES) ((UINT8)TSS_TSI_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState + 1u);
          }
        }
        /* Set Sample Interrupted flag, because TSI measures at background and it can interrupt sampling of GPIO based methods */
        TSS_SET_SAMPLE_INTERRUPTED();
      }
    #endif
    #if TSS_DETECT_MODULE(TSI0)
      #if TSS_KINETIS_MCU
        #if TSS_ENABLE_DIAGNOSTIC_MESSAGES
          #warning TSS - Please assign ISR function TSS_TSI0Isr to vector INT_TSI0
        #endif
      #elif TSS_CFM_MCU
        #if TSS_ENABLE_DIAGNOSTIC_MESSAGES
          #warning TSS - Please assign ISR function TSS_TSI0Isr to vector Vtsi0
        #endif
        #if !TSS_USE_MQX
          interrupt
        #endif
      #endif
      void TSS_TSI0Isr(
        #if TSS_USE_MQX
          void *_isrParameter
        #else
          void
        #endif
        ) 
      {
        UINT16 u16temp;
        
        ((TSS_TSI_MemMapPtr) (TSS_TSI0_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_TSIEN_MASK; /* Due to 0M33Z maskset (unfreeze after restart) */
        if (tss_CSSys.SystemConfig.LowPowerEn)
        {
          #if (TSS_TSI_VERSION==1)
          ((TSS_TSI_MemMapPtr) (TSS_TSI0_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->STATUS = 0xFFFFFFFFu;  /* Clear OUTFRG Status Flag */
          #endif
          ((TSS_TSI_MemMapPtr) (TSS_TSI0_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_OUTRGF_MASK; /* Clear OUTFRG Flag */
          ((TSS_TSI_MemMapPtr) (TSS_TSI0_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS &= ~TSI_GENCS_TSIIE_MASK; /* Disable TSI Interrupt */
          /* Disables LowPower Wake Up */
          u16temp = TSS_GetSystemConfig(System_SystemConfig_Register);
          (void)TSS_SetSystemConfig(System_SystemConfig_Register,(u16temp & ~TSS_LOWPOWER_EN_MASK));  
        } else {
          ((TSS_TSI_MemMapPtr) (TSS_TSI0_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_EOSF_MASK;  /* Clear Flag */
          #ifdef _TSS_TEST
            _TSS_TSIGEN_OFF;         /* Stop generator */
          #endif
          if (TSS_TSI0_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState != TSI_EOSF_STATE_ERROR)
          {
            /* Increment tsi_u8EndOfScanState */
            TSS_TSI0_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState = (TSS_TSI_EOSF_STATES) ((UINT8)TSS_TSI0_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState + 1u);
          }
        }
        /* Set Sample Interrupted flag, because TSI measures at background and it can interrupt sampling of GPIO based methods */
        TSS_SET_SAMPLE_INTERRUPTED();
      }
    #endif
    #if TSS_DETECT_MODULE(TSI1)
      #if TSS_KINETIS_MCU
        #if TSS_ENABLE_DIAGNOSTIC_MESSAGES
          #warning TSS - Please assign ISR function TSS_TSI1Isr to vector INT_TSI1
        #endif
      #elif TSS_CFM_MCU
        #if TSS_ENABLE_DIAGNOSTIC_MESSAGES
          #warning TSS - Please assign ISR function TSS_TSI1Isr to vector Vtsi1
        #endif
        #if !TSS_USE_MQX
          interrupt
        #endif
      #endif
      void TSS_TSI1Isr(
        #if TSS_USE_MQX
          void *_isrParameter
        #else
          void
        #endif
        ) 
      {
        UINT16 u16temp;
        
        ((TSS_TSI_MemMapPtr) (TSS_TSI1_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_TSIEN_MASK; /* Due to 0M33Z maskset (unfreeze after restart) */
        if (tss_CSSys.SystemConfig.LowPowerEn)
        {
          #if (TSS_TSI_VERSION==1)          
          ((TSS_TSI_MemMapPtr) (TSS_TSI1_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->STATUS = 0xFFFFFFFFu;  /* Clear OUTFRG Status Flag */
          #endif          
          ((TSS_TSI_MemMapPtr) (TSS_TSI1_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_OUTRGF_MASK; /* Clear OUTFRG Flag */
          ((TSS_TSI_MemMapPtr) (TSS_TSI1_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS &= ~TSI_GENCS_TSIIE_MASK; /* Disable TSI Interrupt */
          /* Disables LowPower Wake Up */
          u16temp = TSS_GetSystemConfig(System_SystemConfig_Register);
          (void)TSS_SetSystemConfig(System_SystemConfig_Register,(u16temp & ~TSS_LOWPOWER_EN_MASK));  
        } else {
          ((TSS_TSI_MemMapPtr) (TSS_TSI1_METHOD_ROMDATA_CONTEXT.tsi_cpsu32Module))->GENCS |= TSI_GENCS_EOSF_MASK;  /* Clear Flag */
          #ifdef _TSS_TEST
            _TSS_TSIGEN_OFF;         /* Stop generator */
          #endif
          if (TSS_TSI1_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState != TSI_EOSF_STATE_ERROR)
          {
            /* Increment tsi_u8EndOfScanState */
            TSS_TSI1_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState = (TSS_TSI_EOSF_STATES) ((UINT8)TSS_TSI1_METHOD_RAMDATA_CONTEXT.tsi_eEndOfScanState + 1u);
          }
        }
        /* Set Sample Interrupted flag, because TSI measures at background and it can interrupt sampling of GPIO based methods */
        TSS_SET_SAMPLE_INTERRUPTED();
      }
    #endif

  #else /* End of TSS_KINETIS_MCU || TSS_CFM_MCU */
    #error "TSS - Not supported MCU used"
  #endif

#endif /* End of TSS_DETECT_METHOD(TSI) */

